#include "usefulMethods.h"

bool ballsOn = true;
bool paused = false;
bool wireFrame = false;
bool shadeModel = true;
bool normals = false;
int mode = 0;
bool warp_zone_active = false;
bool rotateSkybox = false;
int startingTime = 0;
bool Play_Instant_Replay = false;
bool player_in_hole = true;
bool Hole_Is_Active = false;
bool billardsOn = false;
bool EarthBall = false;
bool fireworksOn = false;
bool Fog_Is_Active = false;
bool Waving_Jumbotron = false;
bool PhongShading = false;
bool ToonBalls = false;
bool JumbotronMesh = false;

GLuint DisplayListIndex = 0;

// Window Dimensions
int window_width = 1600;
int window_height = 1000;

int skybox_num = 0;

freetype::font_data our_font;
Vector3 camera = Vector3();


float RangeRand(float min, float max){
	float d = ((float)rand())/((float)RAND_MAX);
	return (d * (max - min)) + min;
}

string intToString(int number){
   stringstream ss;
   ss << number;
   return ss.str();
}

bool quadraticEq(float a, float b, float c, float & ansPlus, float & ansMinus){
	float discriminant = pow(b, 2.0f) - (4.0f * a * c);
	if(discriminant < 0){
		ansPlus = -100;
		ansMinus = -100;
		return true;
	}
	else{
		ansPlus = (-b + sqrt(discriminant)) / (2.0f*a);
		ansMinus = (-b - sqrt(discriminant)) / (2.0f*a);
		return false;
	}
}

void drawAxis3(float len){
	GLboolean lightingOn;
	glGetBooleanv(GL_LIGHTING, &lightingOn);
	glDisable(GL_LIGHTING);

	glColor3f(1.0,0.0f,0.0f);
	glBegin(GL_LINES);
	glVertex3f(0.0f,0.0f,0.0f);
	glVertex3f(len,0.0f,0.0f);
	glEnd();

	glColor3f(0.0f,1.0f,0.0f);
	glBegin(GL_LINES);
	glVertex3f(0.0f,0.0f,0.0f);
	glVertex3f(0.0f,len,0.0f);
	glEnd();

	glColor3f(0.0f,0.0f,1.0f);
	glBegin(GL_LINES);
	glVertex3f(0.0f,0.0f,0.0f);
	glVertex3f(0.0f,0.0f,len);
	glEnd();

	if (lightingOn)
		glEnable(GL_LIGHTING);
}

void glTranslateVector(Vector3 dis){
	glTranslatef(dis.getCord(0), dis.getCord(1), dis.getCord(2));
}

void getXandZonCircleWithRandTheta(float theta, float radius, float &x, float &z){
	z = -cos(degreesToRadians(theta)) * radius;
	x = sin(degreesToRadians(theta)) * radius;
}

float degreesToRadians(float degrees){
	return degrees * (PI / 180.0f);
}

float radiansToDegrees(float radians){
	return radians * (180.0f / PI);
}

Vector3 randUnitSphereVector(){
	float theta, phi;
	theta = 2 * PI * RangeRand(0, 1);
	phi = acos(2 * RangeRand(0, 1) - 1);

	return Vector3(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta)).normalize();

}

void glVertexVector(Vector3 pos){
	glVertex3f(pos.getCord(0), pos.getCord(1), pos.getCord(2));
}

void glNormalVector(Vector3 norm){
	glNormal3f(norm.getCord(0), norm.getCord(1), norm.getCord(2));
}

void glColorVector(Vector3 color){
	glColor3f(color.getCord(0), color.getCord(1), color.getCord(2));
}
